local dongjie = fk.CreateSkill {
  name = "th_dongjie",
  max_phase_use_time = 1,
}

dongjie:addEffect("active", {
  anim_type = "control",
  prompt = "#th_dongjie",
  interaction = function(self, player)
    local ban = "#th_dongjie-ban:" .. player.id
    local discard = "#th_dongjie-discard"
    local all_choices = { ban, discard, "Cancel" }
    local choices = table.simpleClone(all_choices)
    if player:isNude() then
      table.removeOne(choices, discard)
    end
    return UI.ComboBox{
      choices = choices,
      all_choices = all_choices,
      default = "Cancel"
    }
  end,
  card_num = 0,
  target_num = 1,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local data = self.interaction.data
    local ban = "#th_dongjie-ban:" .. player.id
    local discard = "#th_dongjie-discard"
    local markname = "@@th_dongjie"
    local all_choices = { ban, discard }
    local choices = table.simpleClone(all_choices)
    if data == ban then
      room:addTableMark(player, markname, player.id)
    elseif data == discard then
      room:askToDiscard(player, {
        min_num = 3,
        max_num = 3,
        include_equip = true,
        skill_name = dongjie.name,
        prompt = "#th_dongjie-ask",
        cancelable = false
      })
    end

    table.removeOne(choices, data)
    if target:isNude() then
      table.removeOne(choices, discard)
    end
    if #choices == 0 then return end
    local choice = room:askToChoice(target, {
      all_choices = all_choices,
      choices = choices,
      skill_name = dongjie.name,
      cancelable = false
    })
    if choice == ban then
      room:addTableMark(target, markname, player.id)
    elseif choice == discard then
      room:askToDiscard(target, {
        min_num = 3,
        max_num = 3,
        include_equip = true,
        skill_name = dongjie.name,
        prompt = "#th_dongjie-ask",
        cancelable = false
      })
    end
  end,
}, { check_skill_limit = true })
dongjie:addEffect(fk.PreCardEffect, {
  is_delay_effect = true,
  can_refresh = function(self, event, target, player, data)
    return player:getMark("@@th_dongjie") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    data:setDisresponsive(player)
  end,
})
local lose = {
  is_delay_effect = true,
  can_refresh = function(self, event, target, player, data)
    return target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local markname = "@@th_dongjie"
    for _, to in ipairs(room:getAlivePlayers(false)) do
      if table.contains(to:getTableMark(markname), player.id) then
        room:removeTableMark(to, markname, player.id)
      end
    end
  end,
}
dongjie:addEffect(fk.TurnStart, lose)
dongjie:addEffect(fk.BuryVictim, lose)

Fk:loadTranslationTable{
  ["th_dongjie"] = "冻结",
  [":th_dongjie"] = "出牌阶段限一次，你可以选择一项并可以执行：1.弃置三张牌（不足则全弃）；2.不可响应牌直到你下回合开始或死亡。然后你令一名其他角色选择并执行你本阶段未执行的一项。",

  ["#th_dongjie"] = "冻结：你可以选择一项并可以执行：1.弃置三张牌；2.不可响应牌直到你下回合开始或死亡。<br>然后你令一名其他角色选择并执行你本阶段未执行的一项",
  ["#th_dongjie-ask"] = "冻结：你须弃置三张牌",

  ["#th_dongjie-ban"] = "不可响应牌直到 %src 下回合开始",
  ["#th_dongjie-discard"] = "弃置三张牌（不足则全弃）",

  ["@@th_dongjie"] = "冻结",
}

return dongjie